<?php
// +----------------------------------------------------------------------
// | [RhaPHP System] Copyright (c) 2017 http://www.rhaphp.com/
// +----------------------------------------------------------------------
// | [RhaPHP] 并不是自由软件,你可免费使用,未经许可不能去掉RhaPHP相关版权
// +----------------------------------------------------------------------
// | Author: Geeson <qimengkeji@vip.qq.com>
// +----------------------------------------------------------------------


namespace addons\hlapp\model;

use think\Db;

class HlappProjectSolve extends CommonModel
{
    public function partInfo(){
        return $this->hasOne('HlappPart','id','part');
    }

    /**
     * 获取解决方案信息
     * @param $solveId
     * @return null
     */
    public static function getSolveInfo($solveId)
    {
        $solveInfo = null;
        if ($solveId) {
            $sql = "SELECT
                      solve.id,
                      solve.eId,
                      p.name        pname,
                      p.amamager_id amamagerId,
                      s.name stageName,
                      e.week,
                      case e.status
                        when 1 then '满意'
                        when 0 then '不满意'
                      end status,
                      e.evaluateInfo,
                      e.remark,
                      solve.content solveContent,
                      part.id       partId,
                      part.name     partName,
                      m.id          mId,
                      m.name        memberName,
                      ma.openId openId,
                      m.openId mopenId
                    FROM hl_hlapp_project_solve solve
                      LEFT JOIN hl_hlapp_project_evaluate e ON solve.eId = e.id
                      LEFT JOIN hl_hlapp_project p ON p.id = e.projectId
                      LEFT JOIN hl_hlapp_part part ON part.id = solve.part
                      LEFT JOIN hl_hlapp_member m ON m.id = solve.memberId
                      LEFT JOIN hl_hlapp_member ma ON ma.id = p.amamager_id
                      LEFT JOIN hl_hlapp_type_stage s on s.id = p.stage
                    WHERE solve.delete_time IS NULL AND p.delete_time IS NULL AND part.delete_time IS NULL AND m.delete_time IS NULL
                    AND solve.id = ".$solveId;
            $solveInfo = Db::query($sql);
        }
        if($solveInfo && count($solveInfo) > 0){
            return  $solveInfo[0];
        }else{
            return null;
        }
    }

}